import math


def my_abs(x):
    if not isinstance(x, (int, float)):
        raise TypeError('bad operand type')
    if x >= 0:
        return x
    else:
        return -x


print(my_abs(-10))


# print(my_abs('a'))


# python的函数可以返回多个值
def move(x, y, step, angle):
    nx = x + step * math.cos(angle)
    ny = y + step * math.sin(angle)
    return nx, ny


print(move(100, 100, 60, math.pi / 6))


# 但其实这只是一种假象，Python函数返回的仍然是单一值
# 返回值是一个tuple！但是，在语法上，返回一个tuple可以省略括号，而多个变量可以同时接收一个tuple，
# 按位置赋给对应的值，所以，Python的函数返回多值其实就是返回一个tuple


def quadratic(a, b, c):
    temp = b * b - 4 * a * c
    if a == 0 and c != 0:
        return - b / c, - b / c
    elif a != 0 and temp >= 0:
        x = math.sqrt(temp)
        denominator = 2 * a
        return (a + x) / denominator, (a - x) / denominator
    elif a != 0 and temp <= 0:
        return '无解', '无解'
    else:
        return 'are kidding me?', 'mmp'


print(quadratic(1, 2, 1))
print(quadratic(0, 0, 0))

